﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using Nokia_Portal.Properties;

namespace Nokia_Portal
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public string LocalIPAddress()
        {
            IPHostEntry host;
            string localIP = "";
            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    localIP = ip.ToString();
                    break;
                }
            }
            return localIP;
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            MessageBox.Show(LocalIPAddress());
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            AboutBox1 ss = new AboutBox1();
            ss.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("All the blue text in this application is clickable");
            linkLabel7.Text = "5: Enter " + LocalIPAddress() + " as the APN and 8888 as the Port";
            linkLabel8.Text = "6: Go to http://" + LocalIPAddress() + ":8888/FiddlerRoot.cer";
        }

        private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = @".\DoNotOpen.exe";

            using (Process proc = Process.Start(start))
            { }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Video ss = new Video();
            ss.Show();
        }

        private void linkLabel15_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                System.IO.Directory.CreateDirectory(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Fiddler2");
                System.IO.Directory.CreateDirectory(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Fiddler2\Scripts");
                File.Create(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Fiddler2\Scripts\CustomRules.js").Close();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }

            StreamReader reader = new StreamReader(File.OpenRead(Path.GetDirectoryName(Application.ExecutablePath) + @"\Fiddler2\Scripts\SampleRules.js"));

            string fileContent = reader.ReadToEnd();

            reader.Close();

            fileContent = fileContent.Replace("*;TEMP;*", textBox1.Text);

            StreamWriter writer = new StreamWriter(File.OpenWrite(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Fiddler2\Scripts\CustomRules.js"));

            writer.Write(fileContent);

            writer.Close();


            ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + @"\Fiddler2\Fiddler.exe";

            using (Process proc = Process.Start(start))
            { }
        }

        private void linkLabel14_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                System.IO.Directory.CreateDirectory(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Fiddler2");
                System.IO.Directory.CreateDirectory(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Fiddler2\Scripts");
                File.Create(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Fiddler2\Scripts\CustomRules.js").Close();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }

            StreamReader reader = new StreamReader(File.OpenRead(Path.GetDirectoryName(Application.ExecutablePath) + @"\Fiddler2\Scripts\SampleRules.js"));

            string fileContent = reader.ReadToEnd();

            reader.Close();

            fileContent = fileContent.Replace("*;TEMP;*", textBox1.Text);

            StreamWriter writer = new StreamWriter(File.OpenWrite(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Fiddler2\Scripts\CustomRules.js"));

            writer.Write(fileContent);

            writer.Close();


            ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + @"\Fiddler2\Fiddler.exe";

            using (Process proc = Process.Start(start))
            { }
        }

        private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Visible = Visible;
            Image myImage = Resources.wp_ss_20130713_0003;
            pictureBox1.Image = myImage;
        }

        private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Visible = Visible;
            pictureBox1.Image = Nokia_Portal.Properties.Resources.wp_ss_20130713_0004;
        }

        private void linkLabel7_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Visible = Visible;
            pictureBox1.Image = Nokia_Portal.Properties.Resources.wp_ss_20130713_0004;
        }

        private void linkLabel8_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Visible = Visible;
            pictureBox1.Image = Nokia_Portal.Properties.Resources.wp_ss_20130713_0011;
        }

        private void linkLabel9_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Visible = Visible;
            pictureBox1.Image = Nokia_Portal.Properties.Resources.wp_ss_20130713_0010;
        }

        private void linkLabel10_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Visible = Visible;
            pictureBox1.Image = Nokia_Portal.Properties.Resources.wp_ss_20130713_0006;
        }

        private void linkLabel11_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Visible = Visible;
            pictureBox1.Image = Nokia_Portal.Properties.Resources.wp_ss_20130713_0007;
        }

        private void linkLabel12_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Visible = Visible;
            pictureBox1.Image = Nokia_Portal.Properties.Resources.wp_ss_20130713_0008;
        }

        private void linkLabel13_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Visible = Visible;
            pictureBox1.Image = Nokia_Portal.Properties.Resources.wp_ss_20130713_0009;
        }

        private void linkLabel16_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            panel1.Hide();
        }
    }
}
